//
//  FTYCollectionPort.m
//  RedWine
//
//  Created by Liufangfang on 2017/1/4.
//  Copyright © 2017年 HuiBangKe. All rights reserved.
//

#import "FTYCollectionPort.h"

#define kCollectionSubUrl @"/shop/ybkapi.php?act=ybkapi&op=goodscoll"
#define KCancelCollectionSubUrl @"/shop/ybkapi.php?act=ybkapi&op=cancelcoll"

@implementation FTYCollectionPort

+ (void)requestCollectionWithProjectID:(NSString *)projectID viewController:(UIViewController *)vc block:(ReturnStateBlock)block{
    
    if ([FTYUser sharedUser].userID.length > 0) {
        
        FTYUser *user = [FTYUser sharedUser];
        NSString *url = [NSString stringWithFormat:@"%@&goods_id=%@&member_id=%@", kCollectionSubUrl, projectID, user.userID];
        
        [FTYHTTPManager postInfoWithSubUrl:url parameters:nil block:^(id result, NSError *error) {
            
            if (!error) {
                
                NSLog(@"收藏=====%@", result);
                FTYBaseModel *baseModel = [[FTYBaseModel alloc] init];
                baseModel = [FTYBaseModel mj_objectWithKeyValues:result];
                FTYErrorInfoModel *errorInfo = [FTYErrorInfoModel mj_objectWithKeyValues:baseModel.err];
                
                if (0 == errorInfo.errorcode) {
                    block(YES);
                    [[FTYToastView alloc] addTitle:@"收藏成功" addView:vc.view];
                } else {
                    
                    [[FTYToastView alloc] addTitle:errorInfo.errorinfo addView:vc.view];
                }
            } else {
              
            }
        }];
       
    }else{
        [FTYLoginManager reLoginFromViewController:vc];
//        [[self class] loginAction:vc];
    }
}

+ (void)requestCancelCollectionWithProjectID:(NSString *)projectID viewController:(UIViewController *)vc block:(ReturnStateBlock)block{
    
    if ([FTYUser sharedUser].userID.length > 0) {
        
        FTYUser *user = [FTYUser sharedUser];
        NSString *url = [NSString stringWithFormat:@"%@&goods_id=%@&member_id=%@", KCancelCollectionSubUrl, projectID, user.userID];
        
        [FTYHTTPManager postInfoWithSubUrl:url parameters:nil block:^(id result, NSError *error) {
            
            if (!error) {
                
                
                FTYBaseModel *baseModel = [[FTYBaseModel alloc] init];
                baseModel = [FTYBaseModel mj_objectWithKeyValues:result];
                FTYErrorInfoModel *errorInfo = [FTYErrorInfoModel mj_objectWithKeyValues:baseModel.err];
                
                if (0 == errorInfo.errorcode) {
                    block(NO);
                    [[FTYToastView alloc] addTitle:@"取消收藏成功" addView:vc.view];
                } else {
                    
                    [[FTYToastView alloc] addTitle:errorInfo.errorinfo addView:vc.view];
                }
            } else {
               
            }
        }];
       
    }else{
        [FTYLoginManager reLoginFromViewController:vc];
//        [[self class] loginAction:vc];
    }
}


//+ (void)loginAction:(UIViewController *)vc{
//    
//    RWLoginViewController *loginVC = [[RWLoginViewController alloc] init];
//    FTYNavigationController *loginNC = [[FTYNavigationController alloc] initWithRootViewController:loginVC];
//    loginNC.navigationBar.translucent = NO;
//    loginNC.navigationBar.barTintColor = [FTYColor getMainColorWithAlpha:1.];
//    loginNC.navigationBar.tintColor = [UIColor whiteColor];
//    [loginNC.navigationBar setTitleTextAttributes:@{NSFontAttributeName: FTY_FONTTSIZE(20),
//                                                    NSForegroundColorAttributeName: [UIColor whiteColor]}];
//    [vc presentViewController:loginNC animated:YES completion:nil];
//}

@end
